<?php

/**
 * This is the model class for table "{{bus_trip}}".
 *
 * The followings are the available columns in table '{{bus_trip}}':
 * @property integer $bus_trip_id
 * @property integer $bus_detail_id
 * @property integer $start_time
 * @property integer $end_time
 * @property integer $ordering
 */
class BusTrip extends CActiveRecord {

    public $startTimeShow;
    public $endTimeShow;


    /**
     * Returns the static model of the specified AR class.
     * @param string $className active record class name.
     * @return BusTrip the static model class
     */
    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    /**
     * @return string the associated database table name
     */
    public function tableName() {
        return '{{bus_trip}}';
    }

    /**
     * @return array validation rules for model attributes.
     */
    public function rules() {
        // NOTE: you should only define rules for those attributes that
        // will receive user inputs.
        return array(
            array('bus_detail_id', 'required'),
            array('bus_detail_id, start_time, end_time, ordering', 'numerical', 'integerOnly' => true),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('bus_trip_id, bus_detail_id, start_time, end_time, ordering', 'safe', 'on' => 'search'),
        );
    }

    /**
     * @return array relational rules.
     */
    public function relations() {
        // NOTE: you may need to adjust the relation name and the related
        // class name for the relations automatically generated below.
        return array(
        );
    }

    /**
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels() {
        return array(
            'bus_trip_id' => 'Bus Trip',
            'bus_detail_id' => 'Bus Detail',
            'start_time' => 'Start Time',
            'end_time' => 'End Time',
            'ordering' => 'Ordering',
        );
    }

    /**
     * Retrieves a list of models based on the current search/filter conditions.
     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
     */
    public function search() {
        // Warning: Please modify the following code to remove attributes that
        // should not be searched.

        $criteria = new CDbCriteria;

        $criteria->compare('bus_trip_id', $this->bus_trip_id);
        $criteria->compare('bus_detail_id', $this->bus_detail_id);
        $criteria->compare('start_time', $this->start_time);
        $criteria->compare('end_time', $this->end_time);
        $criteria->compare('ordering', $this->ordering);

        return new CActiveDataProvider($this, array(
                    'criteria' => $criteria,
                ));
    }

    protected function afterFind() {
        parent::afterFind();
        
        list($iHour, $iMinute, $iSecond) = HCTime::sencondsToTime($this->start_time);
        $this->startTimeShow = $iHour . ':' . $iMinute;
        
        list($iHour, $iMinute, $iSecond) = HCTime::sencondsToTime($this->end_time);
        $this->endTimeShow = $iHour . ':' . $iMinute;
    }

}